package com.atguigu.mymvc.listener;

import com.atguigu.mymvc.core.ComponentScan;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import jakarta.servlet.annotation.WebListener;

@WebListener
public class ContextLoaderListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        try {
            Class.forName("com.atguigu.mymvc.core.ComponentScan");
            ServletContext application = sce.getServletContext();
            application.setAttribute("beanFactory", ComponentScan.beanFactory);
            application.setAttribute("controllerBeanMap",ComponentScan.controllerBeanMap);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
